package com.game.commons.concurrent.stats;

import java.lang.Thread.UncaughtExceptionHandler;

import org.apache.log4j.Logger;

/**
 * 该线程由于未捕获到异常而突然终止时调用的处理程序
 * @author 杜祥
 * @date 2012-10-22
 */
public class ThreadUncaughtExceptionHandler implements UncaughtExceptionHandler
{
	private static final Logger log = Logger.getLogger(ThreadUncaughtExceptionHandler.class);
	
	@Override
	public void uncaughtException(Thread t, Throwable e)
	{
		log.error("严重错误 - 线程: " + t.getName() + " 终止异常 " + e, e);
		if (e instanceof OutOfMemoryError)
		{
			// TODO try get some memory or restart
			log.error("内存不足! 需要更多的内存!");
		}
	}

}
